package com.ruoyi.lifecycle.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.excel.utils.ExcelUtil;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.lifecycle.domain.vo.TFundDistributorMilestoneVo;
import com.ruoyi.lifecycle.domain.bo.TFundDistributorMilestoneBo;
import com.ruoyi.lifecycle.service.ITFundDistributorMilestoneService;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;

import java.util.List;
import java.util.Arrays;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.servlet.http.HttpServletResponse;

/**
 * 基金-销售商里程碑控制器
 * 前端访问路由地址为:/lifecycle/fundDistributorMilestone
 *
 * @author chq
 * @date 2025-06-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fundDistributorMilestone")
public class TFundDistributorMilestoneController extends BaseController {

    private final ITFundDistributorMilestoneService iTFundDistributorMilestoneService;

    /**
     * 查询基金-销售商里程碑列表
     */
    @SaCheckPermission("lifecycle:fundDistributorMilestone:list")
    @GetMapping("/list")
    public TableDataInfo<TFundDistributorMilestoneVo> list(TFundDistributorMilestoneBo bo, PageQuery pageQuery) {
        return iTFundDistributorMilestoneService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出基金-销售商里程碑列表
     */
    @SaCheckPermission("lifecycle:fundDistributorMilestone:export")
    @Log(title = "基金-销售商里程碑", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TFundDistributorMilestoneBo bo, HttpServletResponse response) {
        List<TFundDistributorMilestoneVo> list = iTFundDistributorMilestoneService.queryList(bo);
        ExcelUtil.exportExcel(list, "基金-销售商里程碑", TFundDistributorMilestoneVo.class, response);
    }

    /**
     * 获取基金-销售商里程碑详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("lifecycle:fundDistributorMilestone:query")
    @GetMapping("/{id}")
    public R<TFundDistributorMilestoneVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iTFundDistributorMilestoneService.queryById(id));
    }

    /**
     * 新增基金-销售商里程碑
     */
    @SaCheckPermission("lifecycle:fundDistributorMilestone:add")
    @Log(title = "基金-销售商里程碑", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TFundDistributorMilestoneBo bo) {
        return toAjax(iTFundDistributorMilestoneService.insertByBo(bo));
    }

    /**
     * 修改基金-销售商里程碑
     */
    @SaCheckPermission("lifecycle:fundDistributorMilestone:edit")
    @Log(title = "基金-销售商里程碑", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TFundDistributorMilestoneBo bo) {
        return toAjax(iTFundDistributorMilestoneService.updateByBo(bo));
    }

    /**
     * 删除基金-销售商里程碑
     *
     * @param ids 主键串
     */
    @SaCheckPermission("lifecycle:fundDistributorMilestone:remove")
    @Log(title = "基金-销售商里程碑", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
        return toAjax(iTFundDistributorMilestoneService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
